package cn.xwt.weidisk.service.impl;

import cn.xwt.weidisk.service.CommonService;
import cn.xwt.weidisk.util.CommonUtils;
import cn.xwt.weidisk.util.MailUtils;
import cn.xwt.weidisk.util.RedisUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author 薛慰涛
 */
@Service("CommonService")
public class CommonServiceImpl implements CommonService {

    @Resource
    MailUtils mailUtils;
    @Resource
    RedisUtils redisUtils;



    @Override
    public boolean getVerificationCode(String email) {
        // 获取验证码
        String verificationCode = CommonUtils.getVerificationCode();
        // 邮件发送成功，把验证码存入redis中
        if(mailUtils.sendCode(email, verificationCode)) {
            redisUtils.setMinuteExpireKey(email, verificationCode, 5);
            return true;
        } else {
            return false;
        }
    }

    @Override
    public boolean sendEmail(String email, String msg) {
        return mailUtils.sendEmail(email, msg);
    }
}
